function depart()
% Funcion:   depart
% Proposito: Funcion de los eventos de partidas
%
%
global Q_LIMIT;
global BUSY;
global IDLE;

global next_event_type;
global num_custs_delayed;
global num_delays_required;
global num_events;
global num_in_q;
global server_status;

global area_num_in_q;
global area_server_status;
global mean_interarrival;
global mean_service;
global time;
global time_arrival;
global time_last_event;
global time_next_event;
global total_of_delays;
global delayinqueue;
global times_service;
global total_in_system;
global clients_server;
global client_in_server;
global client_departures;

% Chequea si la cola esta vacia
	if ( num_in_q == 0)
		% Para debuguear
		% keyboard ();
		% La cola esta vacia entonces, pone el servidor en libre
		server_status(next_event_type-1)      = IDLE;
		time_next_event(next_event_type) = 1.0e+30;
	else
		% La cola no esta vacia, entonces decrementa el numero de
		%  clientes en cola.
		num_in_q = num_in_q - 1;
		
		% Calcula el delay del cliente que esta comenzando a ser servido
		% y actualiza el acumulador del delay total
		delay            = time - time_arrival(1);
		total_of_delays = total_of_delays + delay;

		% Incrementa el numero de clientes atendidos y programa la
		%  partida.
		num_custs_delayed = num_custs_delayed + 1;
		aux = expon(mean_service);
		time_next_event(next_event_type) = time + aux;
		client_departures(num_custs_delayed) = time_next_event(next_event_type);
		times_service(num_custs_delayed) = aux;
		delayinqueue(num_custs_delayed) = delay;
		client_in_server(next_event_type-1) = num_custs_delayed;
		clients_server(num_custs_delayed) = next_event_type-1;

		% Mueve cada cliente en la cola un lugar.
		for i = 1:num_in_q
			time_arrival(i) = time_arrival(i + 1);
		end
	end
return;

